<?php

use App\Api\CaptchaController;
use App\Api\ConfigController;
use App\Api\LoginController;
use App\Api\MenuController;
use App\Api\PermissionController;
use App\Api\RecordController;
use App\Api\RoleController;
use App\Api\SmsController;
use App\Api\SwiperController;
use App\Api\SystemNotiftyController;
use App\Api\TradeController;
use App\Api\UploadController;
use App\Api\UserController;
use App\Api\VoucherController;
use Illuminate\Support\Facades\Route;

//管理员

Route::post('user/login', [LoginController::class, 'login']);
Route::post('user/logout', [LoginController::class, 'logout']);

Route::get('user/info', [UserController::class, 'info']);


Route::get('user/normal', [UserController::class, 'normal']);
Route::get('user/member', [UserController::class, 'member']);
//审批
Route::get('user/getApprove', [UserController::class, 'getApprove']);
Route::put('user/{user}/agree', [UserController::class, 'agree']);
Route::put('user/{user}/reject', [UserController::class, 'reject']);

Route::resource('user', UserController::class);


Route::get('captcha', [CaptchaController::class, 'make']);

//后台管理

Route::group(['prefix' => 'admin/', 'middleware' => ['auth:sanctum']], function () {
    //==============菜单（嵌套模型）=================
    //获取所有节点

    Route::get('node/getAllNodes', [MenuController::class, 'getAllNodes']);


    Route::post('node/rebuildAllNodes', [MenuController::class, 'rebuildAllNodes']);
    //显示节点
    Route::get('node/show', [MenuController::class, 'showNodes']);
    //初始化
    Route::post('node/initNode', [MenuController::class, 'initNode']);
    //移动节点
    Route::get('node/move', [MenuController::class, 'moveNode']);
    //删除节点
    Route::get('node/delete', [MenuController::class, 'deleteNode']);


    //==============管理员角色=================

    Route::get('user/isAdmin', [UserController::class, 'isAdmin']);

    Route::post('user/forget', [UserController::class, 'forget']);

    Route::post('user/{user}/setAdmin', [UserController::class, 'setAdmin']);

    Route::post('user/{user}/cancelAdmin', [UserController::class, 'cancelAdmin']);

    Route::resource('role', RoleController::class);


    Route::post('user/{user}/syncRoles', [RoleController::class, 'syncRoles']);

    //当前用户拥有的角色
    Route::post('user/{user}/hasRoles', [RoleController::class, 'hasRoles']);


    //==============角色权限=================

    Route::post('permission/init', [PermissionController::class, 'init']);

    Route::post('role/{role}/syncPermissions', [PermissionController::class, 'syncPermissions']);

    Route::post('role/{role}/rolehasPermissions', [PermissionController::class, 'rolehasPermissions']);

    //所有的权限

    Route::get('permission/getAllPermissions', [PermissionController::class, 'getAllPermissions']);


    Route::get('permission/currUserPermission', [PermissionController::class, 'currUserPermission']);


    //==============代金券=================

    Route::resource('voucher', VoucherController::class);
    //批量生成
    Route::post('voucher/patch', [VoucherController::class, 'patch']);
    //卡卷拥有的记录
    Route::post('voucher/{voucher}/record', [VoucherController::class, 'haveRecords']);

    //可兑换代金券

    Route::post('voucher/exchangeable', [VoucherController::class, 'exchangeable']);
    //代金券兑换现金

    Route::post('voucher/{voucher}/withdraw', [TradeController::class, 'withdraw']);


    //==============转移记录=================

    Route::resource('record', RecordController::class);


    //==============系统通知=================

    //系统通知消息
    Route::apiResource('system/notify', SystemNotiftyController::class)->only(['index', 'show']);


    //==============系统配置=================

    //获取系统配置
    Route::get('config', [ConfigController::class, 'info']);
    //修改系统配置
    Route::post('config/update', [ConfigController::class, 'change']);

    //==============短信服务=================

    //获取短信配置
    Route::get('sms', [SmsController::class, 'showsms']);
    Route::put('sms', [SmsController::class, 'putsms']);

    //==============轮播图=================

    //轮播

    Route::resource('swiper', SwiperController::class);


    //==============菜单配置=================

    //生成菜单

    Route::post('menu/generate', [MenuController::class, 'generate']);
});

//==============上传配置=================

//系统功能，本地上传
Route::post('upload/local', [UploadController::class, 'local']);

/**
 * wangEditor编辑器上传
 */
Route::post('upload/wangeditor', [UploadController::class, 'wangEditor']);


//微信小程序
include(__DIR__ . '/miniprogram.php');
